<?php
include_once '../header1.php';
?>

<link href="../style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
require_once '../Login/databaseconnection.php';
if(!loggedin())
{
require_once '../index.php';
}
   
   else
   {
 if(isset($_POST['Search']))
	   {
	   $Competition_Id=$_POST['Competition_Id'];
   $School_Id=$_POST['School_Id'];
	  $Date=$_POST['Date'];
	   
	    if( $Competition_Id=="Select One"||$School_Id=="Select One"||$Date=="Select One")
	   {
		   $_SESSION['errorin1']="Please select the Competition_Id,School_Id and Date!";
	   
	   }
	   else
	   {
	    $result=mysql_query("SELECT * FROM competition WHERE Competition_Id='$Competition_Id' AND School_Id='$School_Id' AND Date='$Date'");
	   if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
	   }
	   
   ?><?php
include_once "../header2.php";
?><?php
include_once "topmenu.php";
?>
<div class="left">
  
<div class="articles">
 <form action="#" method="POST">
 <table width="679" border="0" class="tablefont">
      <tr>
        <td height="18" colspan="4" align="left" scope="row"><?php
		if(isset($_POST['Search']))
{
	if($_SESSION['errorin1']!=" ")
	{
		echo $_SESSION['errorin1'];
		unset($_SESSION['errorin1']);
	}
	if(isset($_SESSION['errornorow']))
	{
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
}
		?></td>
        <td width="74">&nbsp;</td>
        <td width="233">&nbsp;</td>
      </tr>
      <tr>
        <td width="100" rowspan="3" align="left" scope="row" bgcolor="#6AB5FF">Search by</td>
      <td width="101" height="30" align="left" scope="row" bgcolor="#6AB5FF"> Competition Id</td>
      <th width="12" align="left" scope="row" bgcolor="#6AB5FF">:-</th>
      <td width="133" bgcolor="#999999"><select name="Competition_Id" id="select">
	 <?php
	  
	  if(isset($_POST['Search']))
	  {
	 echo '<option value="'.$Competition_Id.'">'.$Competition_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $com=mysql_query("SELECT DISTINCT(Competition_Id) FROM competition");
	  
  while($row=mysql_fetch_array($com))
  {
	 $Competition_Id=$row['Competition_Id'];

	  echo '<option value="'.$Competition_Id.'">'.$Competition_Id.'</option>';
  }
	  ?>
      </select></td>
      <td width="74" rowspan="3" bgcolor="#6AB5FF">Other Way:</td>
      <td width="233" rowspan="3" bgcolor="#999999"><table width="224" border="1">
        <tr>
          <td><input type="text" name="textfield" />
            <input name="SearchOther" align="middle" type="submit" value="Search" /></td>
        </tr>
      </table></td>
      </tr>
    <tr>
      <td align="left" scope="row" bgcolor="#6AB5FF">School Id</td>
      <th width="12" align="left" scope="row" bgcolor="#6AB5FF">:-</th>
      <td bgcolor="#999999"><select name="School_Id" id="select">
        <?php
	  
	  if(isset($_POST['Search']))
	  {
	 echo '<option value="'.$School_Id.'">'.$School_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $com=mysql_query("SELECT DISTINCT(School_Id) FROM competition");
	  
  while($row=mysql_fetch_array($com))
  {
	 $Sch_Id=$row['School_Id'];

	  echo '<option value="'.$Sch_Id.'">'.$Sch_Id.'</option>';
  }
	  ?>
      </select></td>
      </tr>
	
    <tr>
	
      <td height="30" align="left" scope="row" bgcolor="#6AB5FF">Date</td>
      <th height="30" align="left" scope="row" bgcolor="#6AB5FF">:-</th>
      <th height="30" align="left" scope="row" bgcolor="#999999"><select name="Date" id="select">
        <?php
	  
	  if(isset($_POST['Search']))
	  {
	 echo '<option value="'.$Date.'">'.$Date.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $com=mysql_query("SELECT DISTINCT(Date) FROM competition");
	  
  while($row=mysql_fetch_array($com))
  {
	 $Date=$row['Date'];

	  echo '<option value="'.$Date.'">'.$Date.'</option>';
  }
	  ?>
      </select></th>
      </tr>
    <tr>
      <th height="41" colspan="4" align="left"bgcolor="#6AB5FF" scope="row"><a href="SearchComSch.php" class="reset">Reset</a>|
        <input name="Search" align="middle" type="submit" value="Search" /></th>
      <th height="41" colspan="2" align="left"bgcolor="#6AB5FF" scope="row">
      <?php 
	   if(isset($_POST['Search']))
	 {
      if(isset($_SESSION['errornotallo']))
	{
		echo $_SESSION['errornotallo'];
		unset($_SESSION['errornotallo']);
	}
	 }
	?></th>
      </tr>
  </table></form>
   <?php
   
	   if(isset($_POST['Search']))
	   {
	  $Competition_Id=$_POST['Competition_Id'];
   $School_Id=$_POST['School_Id'];
	  $Date=$_POST['Date'];
	  
	   
	  if($Competition_Id!="Select One"&&$School_Id!="Select One"&&$Date!="Select One")
	   {
	    $result=mysql_query("SELECT * FROM competition WHERE Competition_Id='$Competition_Id' AND School_Id='$School_Id' AND Date='$Date'");
  if(mysql_num_rows($result)!=0)
  {
	if($_SESSION['Access_Type']=="Teacher")
{
$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  
   if($School_Id==$Own_School_Id)
	{
	while($row=mysql_fetch_array($result))
  {
    $Competition_Id=$row['Competition_Id'];
   $School_Id=$row['School_Id'];
 $Competition_Name=$row['Competition_Name'];
    $No_Of_Students=$row['No_Of_Students'];
    $No_Of_Teachers=$row['No_Of_Teachers'];
    $Result=$row['Result'];
    $Date=$row['Date'];
    $Scope=$row['Scope'];
   $Winner=$row['Winner'];
		echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "Competition Name:";
		echo '</th>';
        echo '<td width="144">';
		echo "<input type='text' name='Competition_Name' value='$Competition_Name' readonly='readonly'>";
	
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of students:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='No_Of_Students' value='$No_Of_Students' readonly='readonly'>";
		
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of teachers:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='No_Of_Teachers' value='$No_Of_Teachers' readonly='readonly'>";
	
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Result:";
		echo '</th>';
       echo '<td>';
	   echo "<input type='text' name='Result' value='$Result' readonly='readonly'>";
	   
	   echo '</td>';
      echo '</tr>';
     
	 
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Scope:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Scope' value='$Scope' readonly='readonly'>";
	
		echo '</td>';
      echo '</tr>';
	   echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Winner:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Winner' value='$Winner' readonly='readonly'>";
		
		echo '</td>';
      echo '</tr>';
	  }
	  echo '</table>';
	 	 }
		 else
		 {
		  $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
		 }
	 }
	 }
 	else
{
	    echo '<table width="458" border="0">';
 while($row=mysql_fetch_array($result))
  {
    $Competition_Id=$row['Competition_Id'];
   $School_Id=$row['School_Id'];
 $Competition_Name=$row['Competition_Name'];
    $No_Of_Students=$row['No_Of_Students'];
    $No_Of_Teachers=$row['No_Of_Teachers'];
    $Result=$row['Result'];
    $Date=$row['Date'];
    $Scope=$row['Scope'];
   $Winner=$row['Winner'];
  
  echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "Competition Name:";
		echo '</th>';
        echo '<td width="144">';
		echo "<input type='text' name='Competition_Name' value='$Competition_Name' readonly='readonly'>";
	
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of students:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='No_Of_Students' value='$No_Of_Students' readonly='readonly'>";
		
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of teachers:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='No_Of_Teachers' value='$No_Of_Teachers' readonly='readonly'>";
	
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Result:";
		echo '</th>';
       echo '<td>';
	   echo "<input type='text' name='Result' value='$Result' readonly='readonly'>";
	   
	   echo '</td>';
      echo '</tr>';
     
	 
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Scope:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Scope' value='$Scope' readonly='readonly'>";
	
		echo '</td>';
      echo '</tr>';
	   echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Winner:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Winner' value='$Winner' readonly='readonly'>";
		
		echo '</td>';
      echo '</tr>';
    }
    echo '</table>';
	}
	}
	}
	}
   ?>
</div>
</div>
<div class="rightmenu"> 
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php
}
 ?>
</body>
</html>